package com.zhangyujun.bysj.manager.controller;

import com.github.pagehelper.PageInfo;
import com.zhangyujun.bysj.common.log.annotation.Log;
import com.zhangyujun.bysj.manager.service.SysRoleService;
import com.zhangyujun.bysj.model.dto.system.SysRoleDto;
import com.zhangyujun.bysj.model.entity.system.SysRole;
import com.zhangyujun.bysj.model.vo.common.Result;
import com.zhangyujun.bysj.model.vo.common.ResultCodeEnum;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @Author zhangyujun
 * @Date 2024/4/25
 * @Version 1.0
 * @Description TODO
 */
@Tag(name = "系统角色管理")
@RestController
@RequestMapping(value = "/admin/system/sysRole")
public class SysRoleController {
    @Autowired
    private SysRoleService sysRoleService;
    //查询所有角色的方法
    @GetMapping("/findAllRoles/{userId}")
    public Result findAllRoles(@PathVariable("userId")Long userId){
        Map<String,Object> map =  sysRoleService.findAll(userId);
        return Result.build(map,ResultCodeEnum.SUCCESS);
    }
    //删除角色
    @DeleteMapping(value = "/deleteById/{roleId}")
    public Result deleteById(@PathVariable(value = "roleId") Long roleId) {
        sysRoleService.deleteById(roleId) ;
        return Result.build(null , ResultCodeEnum.SUCCESS) ;
    }

    //角色修改
    @PutMapping("/updateSysRole")
    public Result updateSysRole(@RequestBody SysRole sysRole) {
        sysRoleService.updateSysRole(sysRole);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    //角色添加
    @Log(title = "角色管理:添加",businessType = 1)
    @PostMapping("/saveRole")
    public Result saveRole(@RequestBody SysRole sysRole) {
        sysRoleService.saveSysRole(sysRole);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    //角色列表的方法
    @PostMapping("/findByPage/{current}/{limit}")
    public Result findByPage(@PathVariable("current") Integer current,
                             @PathVariable("limit") Integer limit,
                             @RequestBody SysRoleDto sysRoleDto) {
        //pageHelper分页插件
       PageInfo<SysRole> pageInfo = sysRoleService.findByPage(sysRoleDto,current, limit);
       return Result.build(pageInfo, ResultCodeEnum.SUCCESS);
    }
    //添加角色的方法
}
